<template>
	<view class="text-white ">
		<view class="u-flex u-p-l-30 u-p-t-30 u-p-b-30 bg">
			<view class="u-m-r-10 " style="margin-left: 10upx;">
				<image :src="avatar" style="width: 100rpx;height: 100rpx;border-radius: 100rpx;"
					@click="goNav('/pages/my/userinfo')"></image>
			</view>
			<view class="u-flex-1 u-m-l-10 text-white" v-if="!isLogin">
				<view class="u-font-18  text-bold" @click="goNav('/pages/my/userinfo')">
					<view class="margin-right-sm" v-if="XCXIsSelect != '否'">
						<view class="margin-left-sm ">{{userName}}</view>
					</view>
				</view>
			</view>
			<view v-else class="text-xl u-p-l-20 text-bold" @click="goLogin('/pages/public/login')">
				登录
			</view>
		</view>

		<view class="padding-lr-lg padding-bottom-sm flex align-center  bg" v-if="!isLogin">
			<view class="text-center" @click="goNav('/my/wallet/index')" v-if="XCXIsSelect != '否'" style="width: 33%;">
				<view class="text-bold text-lg" style="color: #000;">{{money}}</view>
				<view>我的钱包</view>
			</view>
			<view class="text-center" @click="goNav('/my/youhuijuan/index')" v-if="XCXIsSelect != '否'"
				style="width: 33%;">
				<view class="text-bold text-lg" style="color: #000;">{{youhuijuan}}</view>
				<view>优惠劵</view>
			</view>
			<view class="text-center" @click="goNav('/my/team/team')" style="width: 33%;"
				v-if="yijiyongjin != 0 && XCXIsSelect != '否' && tuandui !='否' && !isLogin">
				<view class="text-bold text-lg" style="color: #000;">{{teamCount}}</view>
				<view>我的团队</view>
			</view>
			<view class="text-center" @click="goNav('/my/gird/browse')" style="width: 33%;">
				<view class="text-bold text-lg" style="color: #000;">{{zujiCount}}</view>
				<view>我的足迹</view>
			</view>
		</view>
		<view class="padding-lr bg" style="position: relative;padding-bottom: 20upx;"
			v-if="XCXIsSelect != '否'&&isVipkg!= '否'">
			<image src="../../static/images/my/bg.png" style="width: 100%;height: 90rpx;" mode=""></image>
			<view class="flex justify-between  margin-lr padding-tb-xs radius"
				style="position: absolute;top: 0;width: 640rpx;">
				<image src="@/static/images/my/huiyuan.png" style="width: 70rpx;height: 70rpx;"></image>
				<view class="flex-sub text-lg"
					style="line-height: 74rpx;color: #604320;margin-left: 20upx;font-weight: bold;">
					开通享受贵族福利
				</view>
				<view v-if="!isVip" class="btn-bg" style="color: #604320;" @click="goNav('/my/vip/index')">去开通</view>
				<view v-if="isVip" class="btn-bg" style="color: #604320;" @click="goNav('/my/vip/index')">已开通</view>
			</view>
		</view>

		<view class="margin bg padding-tb" style="border-radius: 18upx;">
			<view class="flex align-center justify-between padding-lr">
				<view class="text-lg text-bold">我的订单</view>
				<view class="flex align-center" @click="goNav('/my/order/index')">
					查看全部
					<image src="../../static/images/my/right.png" class="images margin-left-xs" mode=""></image>
				</view>
			</view>
			<view class="flex align-center padding-top-sm">
				<view class="text-center" style="width: 25%;position: relative;"
					@click="goNav('/my/order/index?index=1')">
					<image src="../../static/images/my/order1.png" style="width: 55upx;height: 55upx;"></image>
					<view style="color: #666666;">待付款</view>
					<view class="weidu" v-if="order.waitPay">{{order.waitPay}}</view>
				</view>
				<view class="text-center" style="width: 25%;position: relative;"
					@click="goNav('/my/order/index?index=2')">
					<image src="../../static/images/my/order2.png" style="width: 55upx;height: 55upx;"></image>
					<view style="color: #666666;">待服务</view>
					<view class="weidu" v-if="order.progress">{{order.progress}}</view>
				</view>
				<view class="text-center" style="width: 25%;position: relative;"
					@click="goNav('/my/order/index?index=3')">
					<image src="../../static/images/my/order3.png" style="width: 55upx;height: 55upx;"></image>
					<view style="color: #666666;">进行中</view>
					<view class="weidu" v-if="order.waitService">{{order.waitService}}</view>
				</view>
				<view class="text-center" style="width: 25%;" @click="goNav('/my/order/index?index=4')">
					<image src="../../static/images/my/order3.png" style="width: 55upx;height: 55upx;"></image>
					<view style="color: #666666;">已完成</view>
				</view>
			</view>
		</view>

		<view class="margin bg padding-tb" style="border-radius: 18upx;">
			<view class="flex align-center justify-between padding-lr">
				<view class="text-lg text-bold">我的需求</view>
				<view class="flex align-center" @click="goNav('/my/renwu/index')">
					查看全部
					<image src="../../static/images/my/right.png" class="images margin-left-xs" mode=""></image>
				</view>
			</view>
			<view class="flex align-center padding-top-sm">
				<view class="text-center" style="width: 25%;position: relative;"
					@click="goNav('/my/renwu/index?index=1')">
					<image src="../../static/images/my/order1.png" style="width: 55upx;height: 55upx;"></image>
					<view style="color: #666666;">待付款</view>
					<view class="weidu" v-if="order.helpWaitPay">{{order.helpWaitPay}}</view>
				</view>
				<view class="text-center" style="width: 25%;position: relative;"
					@click="goNav('/my/renwu/index?index=2')">
					<image src="../../static/images/my/order2.png" style="width: 55upx;height: 55upx;"></image>
					<view style="color: #666666;">待接单</view>
					<view class="weidu" v-if="order.helpWaitService">{{order.helpWaitService}}</view>
				</view>
				<view class="text-center" style="width: 25%;position: relative;"
					@click="goNav('/my/renwu/index?index=3')">
					<image src="../../static/images/my/order3.png" style="width: 55upx;height: 55upx;"></image>
					<view style="color: #666666;">待服务</view>
					<view class="weidu" v-if="order.helpProgress">{{order.helpProgress}}</view>
				</view>
				<view class="text-center" style="width: 25%;position: relative;"
					@click="goNav('/my/renwu/index?index=4')">
					<image src="../../static/images/my/order4.png" style="width: 55upx;height: 55upx;"></image>
					<view style="color: #666666;">进行中</view>
					<view class="weidu" v-if="order.helpWaiting">{{order.helpWaiting}}</view>
				</view>
				<!-- 	<view class="text-center" style="width: 25%;" @click="goNav('/my/renwu/index?index=4')">
					<image src="../../static/images/my/order3.png" style="width: 55upx;height: 55upx;"></image>
					<view style="color: #666666;">已完成</view>
				</view> -->
			</view>
		</view>

		<view class="margin bg padding-tb" style="border-radius: 18upx;">
			<view class="flex align-center padding-lr">
				<view class="text-lg text-bold">推荐工具</view>
			</view>
			<view class="flex align-center padding-top-sm flex-wrap">
				<view class="text-center margin-bottom-sm" style="width: 25%;position: relative;"
					@click="goNavs('/package/pages/yuangong/index')" v-if="company">
					<image src="../../static/images/my/yuangong.png"
						style="width: 45upx;height: 52upx;margin-top: 10upx;">
					</image>
					<view style="color: #666666;margin-top: 10upx;">员工中心</view>
					<view class="weidu" v-if="ygzsTodoCount">{{ygzsTodoCount}}</view>
				</view>
				<view class="text-center margin-bottom-sm" style="width: 25%;" @click="goshop()">
					<image src="../../static/images/my/ruzhu.png" style="width: 55upx;height: 55upx;margin-top: 10upx;">
					</image>
					<view style="color: #666666;margin-top: 10upx;">商家入驻</view>
				</view>
				<view class="text-center margin-bottom-sm" style="width: 25%;" @click="goshifu()">
					<image src="../../static/images/my/shifuruzhu.png"
						style="width: 55upx;height: 55upx;margin-top: 10upx;">
					</image>
					<view style="color: #666666;margin-top: 10upx;">师傅入驻</view>
				</view>
				<view class="text-center margin-bottom-sm" style="width: 25%;" @click="goNav('/my/renwu/index')">
					<image src="../../static/images/my/renwu.png" style="width: 55upx;height: 55upx;margin-top: 10upx;">
					</image>
					<view style="color: #666666;margin-top: 10upx;">我的需求</view>
				</view>
				<view class="text-center margin-bottom-sm" style="width: 25%;" @click="goNav('/my/wallet/moneylist')">
					<image src="../../static/images/my/bifei.png" style="width: 45upx;height: 55upx;margin-top: 10upx;">
					</image>
					<view style="color: #666666;margin-top: 10upx;">补费明细</view>
				</view>
				<view class="text-center margin-bottom-sm" style="width: 25%;"
					@click="goNav('/my/address/address?id=' + 0)">
					<image src="../../static/images/my/address.png"
						style="width: 55upx;height: 55upx;margin-top: 10upx;"></image>
					<view style="color: #666666;margin-top: 10upx;">我的地址</view>
				</view>
				<view class="text-center margin-bottom-sm" style="width: 25%;"
					@click="goNav('/pages/my/invitationUser')" v-if="XCXIsSelect != '否'">
					<image src="../../static/images/my/yaoqin.png"
						style="width: 55upx;height: 55upx;margin-top: 10upx;"></image>
					<view style="color: #666666;margin-top: 10upx;">邀请好友</view>
				</view>
				<view class="text-center margin-bottom-sm" style="width: 25%;" @click="goNav('/my/feedback/index')"
					v-if="XCXIsSelect != '否'">
					<image src="../../static/images/my/yijian.png"
						style="width: 55upx;height: 55upx;margin-top: 10upx;"></image>
					<view style="color: #666666;margin-top: 10upx;">意见反馈</view>
				</view>
				<view class="text-center margin-bottom-sm" style="width: 25%;"
					@click="goNav('/package/pages/detail/goreport')">
					<image src="../../static/images/my/tousu.png" style="width: 55upx;height: 55upx;margin-top: 10upx;">
					</image>
					<view style="color: #666666;margin-top: 10upx;">我的投诉</view>
				</view>
				<view class="text-center margin-bottom-sm" style="width: 25%;"
					@click="goNav('/package/pages/feedbackIndex/feedbackIndex')" v-if="XCXIsSelect != '否'">
					<image src="../../static/images/my/help.png" style="width: 55upx;height: 55upx;margin-top: 10upx;">
					</image>
					<view style="color: #666666;margin-top: 10upx;">帮助中心</view>
				</view>
				<view class="text-center margin-bottom-sm" style="width: 25%;" @click="goNav('/my/setting/index')">
					<image src="../../static/images/my/set.png" style="width: 55upx;height: 55upx;margin-top: 10upx;">
					</image>
					<view style="color: #666666;margin-top: 10upx;">设置中心</view>
				</view>
			</view>
		</view>

		<u-tabbar :list="tabbarList" :mid-button="true" bg-color="#FFFFFF" active-color="#557EFD"
			inactive-color="#999999">
		</u-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				yijiyongjin: 0,
				avatar: '../../static/logo.png',
				isLogin: true,
				userName: '匿名',
				browse: 0, //浏览数
				fans: 0, //粉丝数
				follow: 0, //关注数
				visitor: 0, //访客数
				userId: '',
				isVip: false,
				invitationCode: '', //邀请码

				geRen: 0,
				Qe: 0,
				XCXIsSelect: '是',
				renzheng: false,
				money: 0,
				teamCount: 0,
				zujiCount: 0,
				tuandui: '否',
				arr: [],
				company: false,
				youhuijuan: 0,

				tabbarList: this.$store.state.list,
				timer: '',
				order: {},
				isVipkg: '否',
				arr1: [],
				ygzsTodoCount: 0,
			}
		},
		onLoad() {
			this.XCXIsSelect = this.$queue.getData("XCXIsSelect");
			this.tuandui = this.$queue.getData("tuandui");

			let that = this;
			// that.$Request.getT('/app/common/type/235').then(res => { //报名成功通知
			// 	if (res.code == 0) {
			// 		if (res.data && res.data.value) {
			// 			that.arr.push(res.data.value)
			// 		}
			// 	}
			// })

			that.$Request.getT('/app/common/type/249').then(res => { //私聊消息通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						that.arr.push(res.data.value)
					}
				}
			})
			that.$Request.getT('/app/common/type/236').then(res => { //退款通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						that.arr.push(res.data.value)
					}
				}
			})
			that.$Request.getT('/app/common/type/312').then(res => { //订单状态通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						that.arr.push(res.data.value)
					}
				}
			})
			that.$Request.getT('/app/common/type/621').then(res => { // 派单成功通知	621
				if (res.code == 0) {
					if (res.data && res.data.value) {
						that.arr1.push(res.data.value)
					}
				}

			})

		},
		onShow() {
			this.isVipkg = this.$queue.getData('isVipkg');
			this.Qe = uni.getStorageSync("Qe")
			this.geRen = uni.getStorageSync("geRen")
			if (this.Qe == 2 || this.geRen == 2) {
				this.renzheng = false
			} else {
				this.renzheng = true
			}
			this.userId = uni.getStorageSync('userId')
			if (this.userId) {

				this.isLogin = false
				this.getUserInfo()
				this.getRenZheng()
				this.getRenZhengs()
				this.getAmount()
				this.getIsVip()
				this.getMoney()
				this.getTeamMoney()
				this.zuji()
				this.getcoupon()
				this.getorderNumber()
				this.timer = setInterval(() => {
					this.getorderNumber()
				}, 3000);
			} else {
				this.isLogin = true
				this.userName = '匿名'
				this.browse = 0
				this.fans = 0
				this.follow = 0
				this.visitor = 0
				this.isVip = false
				this.zujiCount = 0
				this.money = 0
				this.teamCount = 0
				this.youhuijuan = 0
				this.avatar = '../../static/logo.png'
				this.order = {}
				clearTimeout(this.timer)
				this.$store.commit('setTagNum', 0)
			}
			this.getYgzsOrderTodoCount();
		},
		onHide() {
			clearTimeout(this.timer)
		},
		onUnload() {
			clearTimeout(this.timer)
		},
		methods: {
			/**
			 * 获取员工中心待办数量
			 */
			getYgzsOrderTodoCount() {
				this.$Request.get('/app/help/selectWaitServiceOrderCount').then(res => {
					if (res.data) {
						this.ygzsTodoCount = res.data.waitService + res.data.serviceCount;
					}
				})
			},
			getorderNumber() {
				this.$Request.getT('/app/orders/getOrderStatusCount').then(res => {
					if (res.code == 0) {
						this.order = res.data
					}
				});
			},
			getcoupon() {
				this.$Request.getT('/app/couponUser/getMyCouponCount').then(res => {
					if (res.code == 0) {
						this.youhuijuan = res.data
					}
				});
			},

			//我的足迹人数
			zuji() {
				this.$Request.getT('/app/userBrowse/selectAmount').then(res => {
					if (res.code == 0) {
						this.zujiCount = res.data.browse
					}
				});
			},
			//我的团队
			getTeamMoney() {
				this.$Request.getT('/app/orders/selectTeamStatistics').then(res => {
					if (res.code == 0) {
						this.teamCount = res.data.teamCount

					}
				});
			},
			// 我的余额
			getMoney() {
				this.$Request.get("/app/userMoney/selectMyMoney").then(res => {
					if (res.code == 0 && res.data) {
						console.log(res.data.money)
						this.money = res.data.money
					}
				});
			},
			// 跳转商户端
			goshop() {
				let shopAppid = this.$queue.getData('shopAppid')
				//#ifdef MP-WEIXIN 

				if (uni.getStorageSync('sendMsg')) {
					wx.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								// console.log(re)
							}
						},
						fail: (res) => {
							// console.log(res)
						}
					})
				}

				wx.navigateToMiniProgram({
					appId: shopAppid,
					path: '/pages/index/index',
					envVersion: 'release', // 打开正式版
					success(res) {
						// 打开成功
					},
					fail: function(err) {
						console.log(err);
					}
				})
				// #endif 
				//#ifndef MP-WEIXIN
				uni.showModal({
					title: '商家入驻',
					content: '请打开微信搜索【码兄家政端】入驻',
					showCancel: false,
					cancelText: '',
					confirmText: '我知道了',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
				// #endif 
			},
			// 跳转师傅端
			goshifu() {
				let shifuAppid = this.$queue.getData('shifuAppid')
				//#ifdef MP-WEIXIN 
				if (uni.getStorageSync('sendMsg')) {
					wx.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								// console.log(re)
							}
						},
						fail: (res) => {
							// console.log(res)
						}
					})
				}
				wx.navigateToMiniProgram({
					appId: shifuAppid,
					path: '/pages/index/index',
					envVersion: 'release', // 打开正式版
					success(res) {
						// 打开成功
					},
					fail: function(err) {
						console.log(err);
					}
				})
				// #endif 
				//#ifndef MP-WEIXIN
				uni.showModal({
					title: '师傅入驻',
					content: '请打开微信搜索【码兄家政师傅端】入驻',
					showCancel: false,
					cancelText: '',
					confirmText: '我知道了',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
				// #endif 
			},

			goNav(e, name) {
				console.log(e)
				if (this.userId) {
					// #ifdef MP-WEIXIN
					if (uni.getStorageSync('sendMsg')) {
						wx.requestSubscribeMessage({
							tmplIds: this.arr,
							success(re) {
								var datas = JSON.stringify(re);
								if (datas.indexOf("accept") != -1) {
									// console.log(re)
								}
							},
							fail: (res) => {
								// console.log(res)
							}
						})
					}
					// #endif
					uni.navigateTo({
						url: e
					})

				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			goNavs(e, name) {
				console.log(e)
				if (this.userId) {
					// #ifdef MP-WEIXIN
					if (uni.getStorageSync('sendMsg')) {
						wx.requestSubscribeMessage({
							tmplIds: this.arr1,
							success(re) {
								var datas = JSON.stringify(re);
								if (datas.indexOf("accept") != -1) {
									// console.log(re)
								}
							},
							fail: (res) => {
								// console.log(res)
							}
						})
					}
					// #endif
					uni.navigateTo({
						url: e
					})

				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			goLogin(e) {
				uni.navigateTo({
					url: e
				})
			},
			getAmount() {
				this.$Request.get("/app/userBrowse/selectAmount").then(res => {
					if (res.code == 0) {
						this.browse = res.data.browse
						this.fans = res.data.fans
						this.follow = res.data.follow
						this.visitor = res.data.visitor
					}
				});
			},
			getUserInfo() {
				this.$Request.get("/app/user/selectUserById").then(res => {
					if (res.code == 0) {
						this.yijiyongjin = res.data.zhiRate ? res.data.zhiRate : 0;
						this.userName = res.data.userName
						this.invitationCode = res.data.invitationCode
						this.avatar = res.data.avatar ? res.data.avatar : '../../static/logo.png'
						this.isAuthentication = res.data.isAuthentication
						if (res.data && res.data.companyId) {
							if (res.data.companyId != 0 && res.data.companyId != 'null') {
								this.company = true
							} else {
								this.company = false
							}
						}

						console.log(this.company)
						uni.setStorageSync('companyId', res.data.companyId)
						uni.setStorageSync('userType', res.data.userType)
						uni.setStorageSync('isAuthentication', res.data.isAuthentication)

						uni.setStorageSync('avatar', res.data.avatar)
						uni.setStorageSync('invitationCode', res.data.invitationCode)
						uni.setStorageSync('zhiFuBao', res.data.zhiFuBao)
						uni.setStorageSync('zhiFuBaoName', res.data.zhiFuBaoName)

					}
				});
			},
			// 个人认证数据
			getRenZheng() {
				let classify
				this.$Request.get("/app/userCertification/queryInsert?classify=" + 1).then(res => {
					console.log(res)
					if (res.code == 0) {
						if (res.data == null) {
							this.geRen = 0
							uni.setStorageSync("geRen", this.geRen)
						} else if (res.data.status == 0) {
							this.geRen = 1
							uni.setStorageSync("geRen", this.geRen)
						} else if (res.data.status == 1) {
							this.geRen = 2
							uni.setStorageSync("geRen", this.geRen)
						} else if (res.data.status == 2) {
							this.geRen = 3
							uni.setStorageSync("geRen", this.geRen)
						}
					}
				});
			},
			// 企业认证数据
			getRenZhengs() {
				let classify
				this.$Request.get("/app/userCertification/queryInsert?classify=" + 2).then(res => {
					console.log(res)
					if (res.code == 0) {
						if (res.data == null) { //未实名
							this.Qe = 0
							uni.setStorageSync("Qe", this.Qe)
						} else if (res.data.status == 0) { //审核中
							this.Qe = 1
							uni.setStorageSync("Qe", this.Qe)
						} else if (res.data.status == 1) { //已实名
							this.Qe = 2
							uni.setStorageSync("Qe", this.Qe)
						} else if (res.data.status == 2) { //已拒绝
							this.Qe = 3
							uni.setStorageSync("Qe", this.Qe)
						}
					}
				});
			},
			getIsVip() {
				this.$Request.get("/app/UserVip/isUserVip").then(res => {
					if (res.code == 0) {
						this.isVip = res.data
						uni.setStorageSync('isVIP', res.data)
					}
				});
			}

		}
	}
</script>

<style lang="scss">
	page {
		background: #F7F7F7;
	}


	.bg {
		background: #FFFFFF;
	}

	.camera {
		width: 54px;
		height: 44px;

		&:active {
			background-color: #ededed;
		}
	}

	.btn-bg {
		width: 64px;
		height: 28px;
		background: linear-gradient(90deg, #CDA26E 0%, #DCB78A 100%);
		border-radius: 28px;
		text-align: center;
		line-height: 28px;
		margin-top: 4px;
		color: '#604320'
	}

	.images {
		width: 11upx;
		height: 18upx;
	}

	.dfs {
		display: flex;
		align-items: center;
	}

	.lovip {
		width: 100rpx;
		height: 35rpx;
		position: relative;
		top: -39rpx;
	}

	.weidu {
		background: red;
		display: inline-block;
		color: #FFFFFF;
		// padding: 4rpx 15rpx;
		padding: 0rpx 8rpx;
		border-radius: 48%;
		font-size: 24rpx;
		position: absolute;
		top: -10rpx;
		right: 20rpx;
	}
</style>